package 比赛.chuanZhiMoNi;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class F {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int totalFriends = sc.nextInt();
        int first = sc.nextInt();
        Map<Integer,Integer> map = new HashMap<>();
        int[] friends = new int[totalFriends+1];

        for (int i = 1; i < totalFriends+1; i++) {
            friends[i] = sc.nextInt();
            map.put(i,0);
        }
        int max = 0;
        while (map.get(first) == 0){
            map.put(first,1);
            max++;
            first = friends[first];
        }
        System.out.println(max);
    }
}
